package cn.sunshine.ymcc.service.impl;

import cn.sunshine.ymcc.service.ICreatTokenService;
import cn.sunshine.ymcc.util.StrUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.text.Format;
import java.util.concurrent.TimeUnit;

@Service
public class CreatTokenServiceImpl implements ICreatTokenService {
    public static final String TOKEN = "token:%s:%s";
    @Autowired
    private RedisTemplate<Object,Object> redisTemplate;
    @Override
    public String createToken(String courseId) {
    Long loginId = 3L;
    String key = String.format(TOKEN,loginId,courseId);
        String token = StrUtils.getComplexRandomString(6);
        redisTemplate.opsForValue().set(key,token,10, TimeUnit.MINUTES);
        return token;
    }
}
